package com.yksj.healthtalk.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yksj.healthtalk.entity.ShopOrderEntity;
import com.yksj.healthtalk.ui.R;

/**
 * 药品订单列表
 * @author Administrator
 *
 */
public class ServerOrderAdapter extends BaseAdapter{

	
	private LayoutInflater inflater; 
	private ViewHolder holder;
	List<ShopOrderEntity> entities;
	public ServerOrderAdapter(Context context,List<ShopOrderEntity> entities) {
		inflater = LayoutInflater.from(context);
		this.entities = entities;
	}

	@Override
	public int getCount() {
		return entities.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.sever_center_order_item,null);
			holder.order_id = (TextView) convertView.findViewById(R.id.order_id);
			holder.order_money = (TextView) convertView.findViewById(R.id.order_money);
			holder.order_time = (TextView) convertView.findViewById(R.id.order_time);
			holder.order_state = (TextView) convertView.findViewById(R.id.order_state);
			holder.order_name = (TextView) convertView.findViewById(R.id.order_name);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		ShopOrderEntity entity = entities.get(position);
		holder.order_id.setText(entity.getORDER_ID());
		holder.order_money.setText(entity.getTOTAL_MONEY());
		holder.order_time.setText(entity.getORDER_TIME());
		holder.order_state.setText(entity.getORDER_STATE());
		
		String name="";
		for (int i = 0; i < entity.getGoods().size(); i++) {
			name = name+","+entity.getGoods().getJSONObject(i).getString("GOODS_NAME");
		}
		holder.order_name.setText(name);
		holder.order_id.setText(entity.getORDER_ID());
		
		return convertView;
	}
	
	public class ViewHolder{
		TextView order_id;
		TextView order_money;
		TextView order_time;
		TextView order_state;
		TextView order_name;
	}

}
